﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IotClientService.Models.Lg;

/// <summary>
/// 充放电保护数据
/// </summary>
public class LgFmtProtect
{
    /// <summary>
    /// 充电电压上限，单位毫伏
    /// </summary>
    public double? ChargeVoltageUpperLimit { get; set; } = 4250;

    /// <summary>
    /// 放电电压下限，单位毫伏
    /// </summary>
    public double? DischargeVoltageLowerLimit { get; set; } = 2950;

    /// <summary>
    /// 充电电流上限，单位毫安
    /// </summary>
    public double? ChargeCurrentUpperLimit { get; set; } = 19800;

    /// <summary>
    /// 放电电流上限，单位毫安
    /// </summary>
    public double? DischargeCurrentUpperLimit { get; set; } = 19800;

    /// <summary>
    /// 充电容量上限，单位毫安时
    /// </summary>
    public double? ChargeCapacityUpperLimit { get; set; } = 25000;

    /// <summary>
    /// 放电容量上限，单位毫安时
    /// </summary>
    public double? DischargeCapacityUpperLimit { get; set; } = 25000;

    /// <summary>
    /// 恒流电流偏差，单位毫安
    /// </summary>
    public double? ConstantCurrentDeviation { get; set; } = 260;

    /// <summary>
    /// 充电时电压连续下限，单位毫伏
    /// </summary>
    public double? ContinuousVoltageLowerLimitDuringCharge { get; set; } = 2;

    /// <summary>
    /// 连续次数
    /// </summary>
    public int? ContinuousCount { get; set; } = 3;

    /// <summary>
    /// 充电时电压累计下降，单位毫伏
    /// </summary>
    public double? CumulativeVoltageDropDuringCharge { get; set; } = 5;

    /// <summary>
    /// 累计次数
    /// </summary>
    public int? CumulativeCount { get; set; } = 3;

    /// <summary>
    /// 充电时电压瞬间下降，单位毫伏
    /// </summary>
    public double? InstantaneousVoltageDropDuringCharge { get; set; } = 125;

    /// <summary>
    /// 恒流电压波动保护，单位毫伏
    /// </summary>
    public double? ConstantCurrentVoltageFluctuationProtection { get; set; } = 150;

    /// <summary>
    /// 怛压电压波动保护，单位毫伏
    /// </summary>
    public double? OverpressureVoltageFluctuationProtection { get; set; } = 10;

    /// <summary>
    /// 放电电压上升限制，单位毫伏
    /// </summary>
    public double? DischargeVoltageRiseLimit { get; set; } = 20;

    /// <summary>
    /// 放电电压瞬间上升，单位毫伏
    /// </summary>
    public double? InstantaneousVoltageRiseDuringDischarge { get; set; } = 125;

    /// <summary>
    /// 电流电压线偏差保护，单位毫伏
    /// </summary>
    public double? CurrentVoltageLineDeviationProtection { get; set; } = 1500;

    /// <summary>
    /// 恒压电压偏差保护，单位毫伏
    /// </summary>
    public double? ConstantVoltageDeviationProtection { get; set; } = 5;

    /// <summary>
    /// 定时刻最小电压检测，单位毫伏
    /// </summary>
    public double? TimedMinimumVoltageDetection { get; set; } = 800;
    /// <summary>
    /// 检测时间
    /// </summary>
    public int? CheckTime { get; set; } = 1;
    /// <summary>
    /// 恒流电流波动
    /// </summary>
    public int? AnMove { get; set; } = 65;
    /// <summary>
    /// 恒压电流连续上升保护
    /// </summary>
    public int? AnUpProtect { get; set; } = 500;
    /// <summary>
    /// 恒压电流瞬间上升保护
    /// </summary>
    public int? AnSyncUpProtect { get; set; } = 500;
    /// <summary>
    /// 充电时间限制
    /// </summary>
    public int? EInTimeLimit { get; set; } = 0;
    /// <summary>
    /// 放电时间限制
    /// </summary>
    public int? EOutTimeLimit { get; set; } = 0;
    /// <summary>
    /// 负压检测值
    /// </summary>
    public int? CheckPressure { get; set; } = 0;
    /// <summary>
    /// 泄露率上限
    /// </summary>
    public double? RateMax { get; set; } = 0;
    /// <summary>
    /// 保压时间
    /// </summary>
    public int? ProtectTime { get; set; } = 0;
    /// <summary>
    /// 内阻上限,DCIR参数
    /// </summary>
    public double? IRMax { get; set; }
    /// <summary>,DCIR参数
    /// 内阻下限
    /// </summary>
    public double? IRMin { get; set; }

    /// <summary>
    /// 重写ToString方法，连接各个属性的值，值的长度为每行数据的首数字
    /// </summary>
    /// <returns></returns>
    public override string ToString()
    {
        return $"{ChargeVoltageUpperLimit.ToString().PadLeft(5, '0')}" +
               $"{DischargeVoltageLowerLimit.ToString().PadLeft(5, '0')}" +
               $"{ChargeCurrentUpperLimit.ToString().PadLeft(6, '0')}" +
               $"{DischargeCurrentUpperLimit.ToString().PadLeft(6, '0')}" +
               $"{ChargeCapacityUpperLimit.ToString().PadLeft(6, '0')}" +
               $"{DischargeCapacityUpperLimit.ToString().PadLeft(6, '0')}" +
               $"{ConstantCurrentDeviation.ToString().PadLeft(6, '0')}" +
               $"{ContinuousVoltageLowerLimitDuringCharge.ToString().PadLeft(5, '0')}" +
               $"{ContinuousCount.ToString().PadLeft(3, '0')}" +
               $"{CumulativeVoltageDropDuringCharge.ToString().PadLeft(5, '0')}" +
               $"{CumulativeCount.ToString().PadLeft(3, '0')}" +
               $"{InstantaneousVoltageDropDuringCharge.ToString().PadLeft(5, '0')}" +
               $"{ConstantCurrentVoltageFluctuationProtection.ToString().PadLeft(5, '0')}" +
               $"{OverpressureVoltageFluctuationProtection.ToString().PadLeft(5, '0')}" +
               $"{DischargeVoltageRiseLimit.ToString().PadLeft(5, '0')}" +
               $"{InstantaneousVoltageRiseDuringDischarge.ToString().PadLeft(5, '0')}" +
               $"{CurrentVoltageLineDeviationProtection.ToString().PadLeft(5, '0')}" +
               $"{ConstantVoltageDeviationProtection.ToString().PadLeft(5, '0')}" +
               $"{TimedMinimumVoltageDetection.ToString().PadLeft(5, '0')}" +

                $"{CheckTime.ToString().PadLeft(3, '0')}" +
                $"{AnMove.ToString().PadLeft(6, '0')}" +
                 $"{AnUpProtect.ToString().PadLeft(6, '0')}" +
                  $"{AnSyncUpProtect.ToString().PadLeft(6, '0')}" +
                   $"{EInTimeLimit.ToString().PadLeft(3, '0')}" +
                    $"{EOutTimeLimit.ToString().PadLeft(3, '0')}" +
                    $"{CheckPressure.ToString().PadLeft(3, '0')}" +
                     $"{RateMax.ToString().PadLeft(4, '0')}" +
                      $"{CheckPressure.ToString().PadLeft(3, '0')}";

    }

    /// <summary>
    /// 获取ir配方
    /// </summary>
    /// <returns></returns>
    public string ToIRString()
    {
        return this.ToString() + $"{IRMax.ToString().PadLeft(6, '0')}" + $"{IRMin.ToString().PadLeft(6, '0')}";
    }
}

